<template>
<div>
    <div class="cart_head">
            <van-nav-bar
                title="购物车"
                left-text="返回"
                :right-text="islogin?'已登录':'登录'"
                left-arrow
                fixed
                placeholder
                @click-left="onClickLeft"
                @click-right="onClickRight"
                />
    </div>
    <div class="shop_list">
        
        <!--  -->
        <div class="shop"  v-for="(shopitem,shopindex) in cartlist" :key="shopindex">
            <van-checkbox-group v-model="result" ref="checkboxGroup">
                <div class="shop_namea">
                    <van-checkbox :name="shopitem.shop[0].shop_id"></van-checkbox>
                    <p class="shop_name">{{shopitem.shop[0].shop_name}}</p>
                </div>
                <van-card v-for="(gooditem,goodindex) in shopitem.shop" :key="goodindex"
                    :num="gooditem.goods_num"
                    :price="gooditem.total_current_price"
                    :desc="msg+gooditem.origin_price"
                    :title="gooditem.goods_name"
                    :thumb="gooditem.goods_pic"
                    />
            </van-checkbox-group>
        </div>
    </div>
    <div>
        <van-submit-bar :price="3050" button-text="提交订单" @submit="onSubmit">
            <van-checkbox v-model="checked" @click="checkall()">全选</van-checkbox>
            <template #tip>
                你的收货地址不支持同城送, <span @click="onClickEditAddress">修改地址</span>
            </template>
        </van-submit-bar>
    </div>
</div>
</template>

<script>
import {CartList} from '../../api/common'
export default {
    name:'cart',
    data() {
        return {
            checked:'',
            msg:"￥:",
            cartlist:[],
            islogin:false,
            result:[],
            setresult:[]
        }
    },
    created() {
        this.cartShow()
        if(localStorage.token){
            this.islogin = true
            
        }else{
            this.islogin = false
        }
    },
    mounted() {
        
    },
    methods: {
        checkall(){
            if(this.checked){
                this.result = this.setresult
            }else{
                this.result = []
            }
            // console.log(this.checked)
            // console.log(this.result)
            // this.result = this.setresult
        },
       
        onSubmit(){},
        onClickEditAddress(){},
        cartShow(){
            CartList({user_id:localStorage.uid}).then(res=>{
                console.log(res)
                this.cartlist = res.result.data.info
                var cartarr = res.result.data.info
                // console.log(cartarr)
                var arr = cartarr.map((item,index,array)=>{
                    // console.log(item)
                    return item.shop[0].shop_id
                })
                // console.log(arr)
                this.setresult = arr
            })
        },
        onClickLeft(){
            this.$router.go(-1)
        },
        onClickRight(){}
    },
}
</script>

<style lang="less" scoped>
.shop_list{
    width: 100%;
    padding-bottom: 200px;
}
.shop_namea{
    width: 100%;
    display: flex;
}
    .shop{
        width: 100%;
        margin-top: 20px;
        background-color: white;
        border-radius: 30px;
        padding: 30px 10px;
        .shop_name{
            text-align: left;
            height: 60px;
            line-height: 60px;
            font-size: 30px;
            padding-left: 50px;
        }
        .van-card__desc{
            margin-left: -20px;
            margin-top: 50px;
            // text-align: left;
            text-decoration: line-through;
        }
        .van-card__title{
            text-align: left;
        }
        .van-card__price{
            color: #f20;
        }
    }
</style>